package com.it.spirngbootmybatis.controller;

import com.it.spirngbootmybatis.domain.Company;
import com.it.spirngbootmybatis.qury.CompanyQury;
import com.it.spirngbootmybatis.service.CompanyService;
import com.it.spirngbootmybatis.util.RedisConfig;
import com.it.spirngbootmybatis.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CompanyController {
    @Autowired
    CompanyService companyService;
    @Autowired
    RedisConfig redisConfig;

@GetMapping("delete")
    public void delete(Integer id){
    companyService.delete(id);
}
@GetMapping("findAll")
public ResultUtil findAll(){
    List<Company> companies = companyService.findAll();
    return companies!=null?new ResultUtil(ResultUtil.SUCCESS,"查询成功！",companies):new ResultUtil(ResultUtil.FAIL,"查询失败");
}
@GetMapping("findByConditon")
    public ResultUtil findByCondition(CompanyQury companyQury){
    List<Company> companies = companyService.findByCondition(companyQury);
    return companies!=null?new ResultUtil(ResultUtil.SUCCESS,"查询成功！",companies):new ResultUtil(ResultUtil.FAIL,"查询失败");
}
@GetMapping("setRedis")
    public void setRedis(String name){
    redisConfig.setKey("name",name);
}
@GetMapping("getRedis")
    public String getRedis() {
    return redisConfig.getKey("name");
}

}
